// $Id: bool.cpp 2 2009-09-02 08:47:42Z joseph2002 $
/*
 * Copyright 2009 Joseph Wu
 * Distributed under the Boost Software License, Version 1.0.
 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
 *
 * For more information, see http://xpcomplus.sourceforge.net
 */

#include <boost/test/unit_test.hpp>
#include <xpcom/impl/bool.hpp>

namespace xpcom {
namespace {

void do_out_impl(bool& b, bool t)
{
    BOOST_CHECK(b == t);
    b = !b;
}

void do_out(bool_t* b, bool t)
{
    do_out_impl(impl::bool_out(b), t);
}

bool do_out_impl_retval()
{
    return true;
}

void do_out_retval(bool_t* b)
{
    impl::bool_out retval(b);
    retval = do_out_impl_retval();
}

void do_inout_impl(bool& b, bool t)
{
    BOOST_CHECK(b == t);
    b = !b;
}

void do_inout(bool_t* b, bool t)
{
    do_inout_impl(impl::bool_inout(b), t);
}

}
}

BOOST_AUTO_TEST_CASE(test_bool_in)
{
    using namespace xpcom;

    bool_t b = false_;
    BOOST_CHECK(!impl::bool_in(b));

    b = true_;
    BOOST_CHECK(impl::bool_in(b));
}

BOOST_AUTO_TEST_CASE(test_bool_out)
{
    using namespace xpcom;

    bool_t b = false_;
    do_out(&b, false);
    BOOST_CHECK(b == true_);

    b = true_;
    do_out(&b, false);
    BOOST_CHECK(b == true_);

    b = false_;
    do_out_retval(&b);
    BOOST_CHECK(b == true_);
}

BOOST_AUTO_TEST_CASE(test_bool_inout)
{
    using namespace xpcom;

    bool_t b = false_;
    do_inout(&b, false);
    BOOST_CHECK(b == true_);

    b = true_;
    do_inout(&b, true);
    BOOST_CHECK(b == false_);
}
